package co.uk.j_wp.games.topdowngame.entity;

import co.uk.j_wp.games.topdowngame.Screen;
import co.uk.j_wp.games.topdowngame.level.Level;

public class Player extends Entity {
	
	private int[] colors = { 20, 20, 20, 20, 20, 0, 0, 20, 20, 0, 0, 20, 20, 20, 20, 20 };
	private int d = 1;
	
	public Player(Level l) {
		super(l);
		width = 4;
		height = 4;
	}

	@Override
	public void draw(Screen s, int xo, int yo) {
		s.setPixels(width, height, (int) posx - xo, (int) posy - yo, colors);
	}

	@Override
	public void tick() {
		super.tick();
		int rposx = posx;
		int rposy = posy;

		if (level.game.key.right) {
			posx += d;
		}
		if (level.game.key.left) {
			posx -= d;
		}
		if (!canMove()) {

			posx = rposx;
			posy = rposy;
		}

		// reset rpos
		rposx = posx;
		rposy = posy;

		if (level.game.key.up) {
			posy -= d;
		}
		if (level.game.key.down) {
			posy += d;
		}

		if (!canMove()) {

			posx = rposx;
			posy = rposy;
		}

		if ((tick++ % 100) < 50) {
			colors[5] = 20;
			colors[6] = 20;
			colors[9] = 20;
			colors[10] = 20;
		} else {
			colors[5] = 0;
			colors[6] = 0;
			colors[9] = 0;
			colors[10] = 0;
		}
	}
}
